import 'package:flutter/material.dart';

class CustomActionInputField extends StatefulWidget {
  final String hintText;
  final ValueChanged<String>? onTextChanged;

  const CustomActionInputField({
    super.key,
    required this.hintText,
    this.onTextChanged,
  });

  @override
  CustomActionInputFieldState createState() => CustomActionInputFieldState();
}

class CustomActionInputFieldState extends State<CustomActionInputField> {
  final TextEditingController _controller = TextEditingController();

  @override
  void initState() {
    super.initState();
    _controller.addListener(_onTextChanged);
  }

  @override
  void dispose() {
    _controller.removeListener(_onTextChanged);
    _controller.dispose();
    super.dispose();
  }

  void _onTextChanged() {
    if (widget.onTextChanged != null) {
      widget.onTextChanged!(_controller.text);
    }
  }

  @override
  Widget build(BuildContext context) {
    return TextField(
      controller: _controller,
      // 核心样式配置
      decoration: InputDecoration(
        // 1. 设置提示文本
        hintText: widget.hintText,
        // 2. 开启背景填充
        filled: true,
        // 3. 设置浅灰色填充颜色
        fillColor: const Color(0xFFF5F6FA), // 接近图片的浅灰色
        
        // 4. 内容边距（可选，用于微调文本位置）
        contentPadding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 10.0),

        // 5. 移除默认的底部下划线/边框 
        border: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10.0), // 设置圆角
          borderSide: BorderSide.none, // 移除边框线
        ),

        // 6. 移除获得焦点时的边框线 
        focusedBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10.0),
          borderSide: BorderSide.none,
        ),
        
        // 7. 移除非激活状态时的边框线
        enabledBorder: OutlineInputBorder(
          borderRadius: BorderRadius.circular(10.0),
          borderSide: BorderSide.none,
        ),
        
        // 8. 提示文字的样式
        hintStyle: TextStyle(
          color: Color(0XFF999999),
          fontSize: 15.0,
        ),
      ),
    );
  }
}